﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DAL;

namespace BLL.Admin
{
    public class NgonNguDao
    {
        public int NgonNguId { set; get; }
        public string Ten { set; get; }
    }
    public class DMNgonNguHelper
    {
        public static void AddNgonNgu(string ten)
        {
            var db = Connect.GetDataContext<TimViecDataContext>("Strconnect");
            db.tbl_DM_NgonNgus.InsertOnSubmit(new tbl_DM_NgonNgu
                                                  {
                                                      MoTa = ten
                                                  });
            db.SubmitChanges();
        }

        public static void UpdadeNgonNgu(int id,string ten)
        {
            var db = Connect.GetDataContext<TimViecDataContext>("Strconnect");
            var ngonNgu = db.tbl_DM_NgonNgus.FirstOrDefault(r => r.NgonNguId == id);
            if(ngonNgu!=null)
            {
                ngonNgu.MoTa = ten;
                db.SubmitChanges();
            }
        }

        public static List<NgonNguDao> ListNgonNgu()
        {
            var db = Connect.GetDataContext<TimViecDataContext>("Strconnect");
            var query = db.tbl_DM_NgonNgus.Select(r => new NgonNguDao
                                                           {
                                                               NgonNguId = r.NgonNguId,
                                                               Ten = r.MoTa
                                                           }).ToList();
            query.Add(new NgonNguDao {NgonNguId = 0, Ten = " "});

            return query.OrderBy(r => r.Ten).ToList();
        }
    }
}